import { Message } from 'iview'

/**
 * @param msg
 * @param type
 */
const showStatusMsg = function (msg = '请指明操作！', type = 'info') {
  Message[type]({
    content: msg, // 请区分element UI 和iview版Message用法
  })
}
/**
 * 普通消息
 */
const showMsg = function (msg = '提示消息') {
  showStatusMsg(msg)
}
const showWarnMsg = function (msg = '警告消息') {
  showStatusMsg(msg, 'warning') // ele: warn    iview: warning
}
/***
 * 操作成功
 * @param msg
 * @param type
 */
const showSuccessMsg = function (msg = '操作成功', type = 'success') {
  showStatusMsg(msg, type)
}
/**
 * 操作失败
 */
const showFailMsg = function (msg = '操作失败', type = 'error') {
  showStatusMsg(msg, type)
}
const Log = function (info, flag = true) {
  if (flag) {
    window.console.log(info)
  }
}
const getPrefix = function (_this) {
  return _this && _this.utilHelper.apiUrl
}
const getQueryString = function (name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
  var r = window.location.search.substr(1).match(reg)
  if (r != null) {
    return unescape(r[2])
  }
  return null
}
const showCustomerInfo = function () {
  var includeCompanyUuids = [
    '2b53ec3f-9c83-11e8-b93d-000c2979eb04', // 测试环境公司
    '4e350cdb-4ee4-4494-80e1-de2a677dfda1', // 生产: 三合
    '9e4e724b-b109-11e8-89a5-005056889b83' // 生产: 巧房演示
  ]
  var companyUuid = getQueryString('companyUuid');
  return includeCompanyUuids.indexOf(companyUuid) >= 0
}
export default {
  showMsg,
  showWarnMsg,
  showStatusMsg,
  showSuccessMsg,
  showFailMsg,
  Log,
  getPrefix,
  getQueryString,
  showCustomerInfo
}
